<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddColumnCategoryTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $prefix = config('ibrand.app.database.prefix', 'ibrand_');
        if (Schema::hasTable($prefix . 'category')) {
            Schema::table($prefix . 'category', function (Blueprint $table) {
                $table->integer('level')->default(1)->after('parent_id');
                $table->string('path')->nullable()->default('/')->after('parent_id');
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        $prefix = config('ibrand.app.database.prefix', 'ibrand_');
        if (Schema::hasTable($prefix . 'category')) {
            Schema::table($prefix . 'category', function (Blueprint $table) {
                $table->dropColumn(['level']);
            });
        }
    }
}
